﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using dAmnSharp;
using System.Threading;

namespace TestApp.cs
{
    class Program
    {
        private class dAmnAbuser
        {
            string[] rooms = { "a", "b", "c", "datashare", "botdom", "geekart", "serverdom", "d", "@plaguethenet", "@shipoopi", "@testuser", "@nono" };
            dAmn d = new dAmn();
            int tNum = -1;
            Thread myThread;
            public dAmnAbuser(int threadNum)
            {
                tNum = threadNum;
                myThread = new Thread(ThreadRun);
                myThread.Start();
            }
            static Random r = new Random();
            public void ThreadRun(object state)
            {
                d.password = "12345678901234567890123456789012";
                d.username = "test";
                d.server = "localhost";
                d.port = 3900;
                d.StateChange += delegate(states newState)
                {
                    Console.WriteLine("STATE CHANGE FOR {0}: {1}", tNum, newState);
                    switch (newState)
                    {
                        case states.LOGGEDIN:
                            d.join("#Botdom");
                            d.join("#Geekart");
                            d.join("#DataShare");
                            d.join("#ServerDom");
                            d.join("#debug");
                            for (int i = 0; i < 200; i++)
                            {
                                d.say("#Botdom", "Channel lag test.");
                                d.say("#Geekart", "Channel lag test.");
                                d.say("#DataShare", "Channel lag test.");
                                d.say("#ServerDom", "Channel lag test.");
                                d.say("#debug", "Channel lag test.");
                                Thread.Sleep(1000);
                            }
                            break;
                    }

                };
                d.Connect();
                Thread.Sleep(1000);
                while (d.state != states.DISCONNECTED)
                {
                    Thread.Sleep(1000);
                }
            }
        }

        static void Main(string[] args)
        {
            List<dAmnAbuser> threads = new List<dAmnAbuser>();
            int x = 0;
            int maxCompletionThreads = 0, maxNormalThreads = 0;
            ThreadPool.GetMaxThreads(out maxNormalThreads, out maxCompletionThreads);
            Console.WriteLine("Thread Pool MaxThreads: {0}, Max AsyncIO threads: {1}", maxNormalThreads, maxCompletionThreads);
            while (true)
            {
                x++;
                Console.WriteLine("Press enter to start another thread.");
                Console.ReadLine();
                threads.Add(new dAmnAbuser(x));
            }

            //GC.KeepAlive(threads);
        }

    }
}
